# ---------- ---------- ---------- ---------- ---------- ----------
#
# effort_metrics
#
#    1) config, vars, and target
#    2) functions
#    3) phonies
#
# ---------- ---------- ---------- ---------- ---------- ----------


target: help


# ---------- ---------- ---------- ---------- ---------- ----------
# functions
# ---------- ---------- ---------- ---------- ---------- ----------

define fix-python
	@pyclean ./src/ ./tests/
	@ruff check --select I --fix . || echo "ruff fix returned nonzero"
	@ruff format . || echo "ruff format returned nonzero"
endef


define lint
	@ruff check . || echo "ruff returned nonzero"
endef


define lint-types
	@mypy . || echo "mypy returned nonzero"
endef


define find-cve
	@pip-audit --skip-editable || echo "pip-audit returned nonzero"
endef


define run-tests
	@coverage run --source='.' -m unittest discover -s tests.effort_metrics_tests -t .
	@coverage report -m | grep -v '100\%'
endef


# ---------- ---------- ---------- ---------- ---------- ----------
# phonies
# ---------- ---------- ---------- ---------- ---------- ----------

.PHONY: help
help:
	@echo "Usage: make [PHONY] [OPTIONS]"
	@sed -n -e "/sed/! s/\.PHONY: //p" Makefile


.PHONY: clean
clean:
	@pyclean ./src/ ./tests/ || echo "pyclean not installed"
	@rm -rf .coverage .mypy_cache .ruff_cache .venv var


.PHONY: clean-docker
clean-docker:
	@service docker restart


.PHONY: fix-python
fix-python:
	@$(call fix-python)


.PHONY: lint
lint:
	@$(call lint)


.PHONY: lint-types
lint-types:
	@$(call lint-types)


.PHONY: find-cve
find-cve:
	@$(call find-cve)


.PHONY: dev
dev: fix-python lint test


.PHONY: dev-all
dev-all: fix-html fix-python lint lint-types find-cve test


.PHONY: test
test:
	@$(call run-tests)
